package com.thwj.common.core.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.thwj.common.core.entity.BizActivityCategory;
import com.thwj.common.core.entity.BizArea;
import com.thwj.common.core.entity.BizUser;
import com.thwj.common.core.service.BizActivityCategoryService;
import com.thwj.common.core.service.BizAreaService;
import com.thwj.common.core.service.BizUserService;
import com.thwj.framework.web.domain.R;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 *Description:
 *首页相关查询
 *@return 
 *@author 宋海涛
 *@since 14:26 2025/1/19
 **/
@RestController
@AllArgsConstructor
@RequestMapping("/homePage")
public class HomeSearchController implements ApplicationRunner {

    @Autowired
    private BizUserService bizUserService;

    @Autowired
    private BizAreaService bizAreaService;

    @Autowired
    private BizActivityCategoryService bizActivityCategoryService;

    //获取基础的活动信息
    @RequestMapping("/getBaseActive")
    public R<List<BizUser>> getBaseActive(@RequestParam(value = "type" ,required = false) String type,
                                                    @RequestParam(value = "beginTime" ,required = false) String beginTime,//开始时间
                                                    @RequestParam(value = "endTime" ,required = false) String endTime,//结束时间
                                                    @RequestParam(value = "category",required = false) String category,//分类
                                                    @RequestParam(value = "prov",required = false) String prov,//地区
                                                    @RequestParam(value = "city",required = false) String city,//城市
                                                    @RequestParam(value = "district",required = false) String district//区县
    ){
        QueryWrapper<BizUser> queryWrapper = new QueryWrapper();
        queryWrapper.eq("type",type);
        queryWrapper.in("category_id",type);
        queryWrapper.gt("star_date",beginTime);
        queryWrapper.le("end_date",endTime);
        queryWrapper.eq("code_prov",prov);
        queryWrapper.eq("code_city",city);
        queryWrapper.eq("code_district",district);
        return R.data(bizUserService.list(queryWrapper), "成功");
    }

    //获取区县信息
    @RequestMapping("/getArea")
    public R<List<BizArea>> getArea(){
        QueryWrapper<BizArea> queryWrapper = new QueryWrapper();
        List<BizArea> areaList = bizAreaService.list(queryWrapper);
        return R.data(bizAreaService.list(queryWrapper), "成功");
    }

    //获取分类信息
    @RequestMapping("/getCategory")
    public R<List<BizActivityCategory>> getCategory(){
        QueryWrapper<BizActivityCategory> queryWrapper = new QueryWrapper();
        queryWrapper.groupBy("order_weight");//根据权重排序
        return R.data(bizActivityCategoryService.list(queryWrapper), "成功");
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
//        System.out.println("开始查询");
//        QueryWrapper<BizActivityCategory> queryWrapper = new QueryWrapper();
//        queryWrapper.orderByAsc("order_weight");//根据权重排序
//        List<BizActivityCategory> areaList =bizActivityCategoryService.list(queryWrapper);
//        System.out.println(areaList);

    }
}
